#!/bin/bash
set -e

# 全局变量
export REDIS_SOURCE_DIR=/root/redis-5.0.5
export BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# 节点扩容：新增一主一从
read -p "新增一主一从: "
cd ${BASE_DIR}/master1
./bin/redis-cli --cluster add-node 172.17.0.4:7004 172.17.0.4:7001

# 重新分配节点
read -p "重新分配槽给新的节点: "
./bin/redis-cli --cluster reshard 172.17.0.4:7004

# 将8004节点作为7004的从节点
read -p "将8004节点作为7004的从节点: "
cd ${BASE_DIR}/master1
./bin/redis-cli --cluster add-node 172.17.0.4:8004 172.17.0.4:7004 \
 --cluster-slave --cluster-master-id 08c88cf3e5dc81675131e038eb6a831e64942e39